package com.kingyun.sercurity.reinforcement.config;

import com.kingyun.sercurity.reinforcement.filter.SecurityReinforcementFilter;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;

import javax.servlet.Filter;

public class CustomWebApplicationInitializer extends AbstractDispatcherServletInitializer {
    protected WebApplicationContext createServletApplicationContext() {
        return null;
    }

    protected String[] getServletMappings() {
        return new String[]{"/*"};
    }

    protected WebApplicationContext createRootApplicationContext() {
        AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
        //        applicationContext.setConfigLocation("com.git.hui.spring");

        System.out.println("-------------------");

        return applicationContext;
    }


    @Override
    protected Filter[] getServletFilters() {
        return new Filter[]{new CharacterEncodingFilter("UTF-8", true), new SecurityReinforcementFilter()};
    }
}
